<template>
    <div class="navbar">
        <van-nav-bar title="评价" right-text="提交" left-arrow @click-left=$router.go(-1) @click-right="onClickRight" />
    </div>
    <br>
    <br>
    <div class="rate">
        <div class="left">
            商品评价
        </div>
        <div class="right">
            <van-rate v-model="value" @change="onChange" />
        </div>
    </div>
    <div class="inppart">
        <van-cell-group inset>
            <van-field v-model="message" rows="2" autosize type="textarea" maxlength="50" placeholder="希望您的评价可以给其他用户带来帮助"
                show-word-limit label-width="60px" />
        </van-cell-group>
    </div>
</template>

<script lang="ts" setup>
import { useRoute } from 'vue-router';
import { onMounted, ref } from 'vue';
import { showToast } from 'vant';
import router from '@/router';
import { useUserInfoStore } from '@/stores/useInfo';
import { AddComon } from '@/api/api';


const store = useUserInfoStore()
const userid = store.getUserId
const value = ref(0)
const proitem = ref<any[]>([])
const message = ref('')
const route = useRoute()
const proid = route.query.proid
const time = Date.now()

const onChange = (val: any) => {
    console.log(val);
}



onMounted(() => {

})

const onClickRight = async () => {//提交按钮
    if (!value.value || !message.value) {
        console.log(111);
        showToast({
            message: '请输入内容',
            position: 'middle'
        })
    } else {
        const params = {
            userid,
            proid,
            message: message.value,
            value: value.value,
            time
        }
        const res = await AddComon(params)
        console.log(res);
        showToast({
            message: '评价成功',
            position: 'middle'
        })
        router.push('/car')
    }
}

</script>

<style lang="scss" scoped>
.rate {
    display: flex;
    line-height: 25px;

    .left {
        margin: 0 20px;
    }
}
</style>